﻿@{
	ViewBag.Title = "Weapons_Index";
	Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="layuimini-container">
	<div class="layuimini-main">

		@* 搜索信息 *@
		<fieldset class="table-search-fieldset layui-hide" id="searchField">
			<div>
				<form class="layui-form layui-form-pane" action="">
					<div class="layui-form-item">
						<div class="layui-inline">
							<div class="layui-input-inline">
								<input type="text" name="keyword" autocomplete="off" placeholder="请输入关键词" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
						</div>
					</div>
				</form>
			</div>
		</fieldset>
		@* 数据表格顶部按钮 *@
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container" id="toolbar">
				<button id="NF-add" name="NF-add" authorize class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</button>
				<button id="NF-edit" name="NF-edit" authorize class="layui-btn layui-btn-sm layui-btn-warm layui-hide" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</button>
				<button id="NF-delete" name="NF-delete" authorize class="layui-btn layui-btn-sm layui-btn-danger layui-hide" lay-event="delete"> <i class="layui-icon">&#xe640;</i>删除</button>
			</div>
		</script>
		@* 行按钮 *@
		<script type="text/html" id="currentTableBar">
			<a id="NF-delete" authorize class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
		</script>
		@* 数据表格 *@
		<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
	</div>
</div>

<script type="text/javascript">
	layui.use(['jquery', 'form', 'table', 'common', 'layer', 'optimizeSelectOption', 'commonTable','laydate'], function () {
		var $ = layui.jquery,
			laydate=layui.laydate,
			form = layui.form,
			table = layui.table,
			layer = layui.layer,
			commonTable = layui.commonTable,
			common = layui.common;

		//权限控制(js是值传递)
		currentTableBar.innerHTML = common.authorizeButtonNew(currentTableBar.innerHTML);
		toolbarDemo.innerHTML = common.authorizeButtonNew(toolbarDemo.innerHTML);

		// 数据表格
		commonTable.rendertable({
			elem: '#currentTableId',
			id: 'currentTableId',
			url: '/STZBManage/User/Get_Weapons_GridJson',
			filter: {
				clearFilter: false
			},
			limit:50, //默认显示50条数据
			cols: [[
				{ type: "checkbox", width: 50, fixed: 'left'},
				{ field: 'Name', title: '武器名称', minWidth: 120, sort: true, filter: true },
				{ field: 'Entry', title: '武器词条', minWidth: 120, sort: true , filter: true},
				{ field: 'Gear', title: '武器档位', minWidth: 120, sort: true, filter: true },
				{ field: 'Price', title: '四通价格', minWidth: 120, sort: true, filter: true},
				{ field: 'CreateTime', title: '注册时间', minWidth: 120, sort: true , filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }},
				{ field: 'UpdateTime', title: '修改时间', minWidth: 120, sort: true , filter: { type: 'date[yyyy/MM/dd HH:mm:ss]' }},
				{ title: '操作', width: 80, toolbar: '#currentTableBar', align: "center", fixed: 'right' }
			]]
		});
		wcLoading.close(); //关闭加载窗
		// 监听搜索操作
		form.on('submit(data-search-btn)', function (data) {
			//执行搜索重载
			commonTable.reloadtable({
				elem: 'currentTableId',
				curr: 1, //页数
				where: { //参数
					keyword: data.field.keyword
				}
			});
			return false;
		});
		//行点击事件监听，控制按钮显示
		var oneList = ["NF-delete","NF-edit"];//选择1条显示
		var morerList = ["NF-delete"];//选中1条以上显示
		//commonTable.tableRowClick("radio", "currentTableFilter", "currentTableId", oneList, morerList); //单选框
		commonTable.tableRowClick("checkbox", "currentTableFilter", "currentTableId", oneList, morerList); //多选框
		//头部按钮监听事件
			table.on('toolbar(currentTableFilter)', function (obj) {
				var data = table.checkStatus('currentTableId').data;
				var id = data.length > 0 ?data[0].Id:null;
				 if (obj.event === 'delete') { //删除按钮
					if (data.length == 0) {
						common.modalMsg("未选中数据", "warning");
						return false;
					}
					var ids = [];
					for (var i = 0; i < data.length; i++) {
						ids.push(data[i].Id);
					}
					common.deleteForm({
						url: "/STZBManage/User/Delete_Weapons",
						param: { ids: ids.join(',') },
						success: function () {
							common.reload('data-search-btn');
						}
					});
				}
				else if(obj.event === 'add'){ //添加按钮
					 common.modalOpen({
						title: "添加",
						url: "/STZBManage/Weapons/Form",
						width: "780px",
						height: "550px"
					});
				}
				else if(obj.event === 'edit'){ //编辑按钮
					common.modalOpen({
						title: "编辑",
						url: "/STZBManage/Weapons/Details?Id="+id,
						width: "780px",
						height: "550px"
					});
				}
				else if (obj.event === 'TABLE_SEARCH') { //搜索按钮
					var _that = $("#searchField");
					if (_that.hasClass("layui-hide")) {
						_that.removeClass('layui-hide');
					} else {
						_that.addClass('layui-hide');
					}
					table.resize();
				}
				return false;
			});
			//行数据按钮监听事件
			table.on('tool(currentTableFilter)', function (obj) {
				var id = obj.data.Id;

				if (obj.event === 'delete') { //删除按钮
					common.deleteForm({
						url: "/STZBManage/User/Delete_Weapons",
						param: { ids: id },
						success: function () {
							obj.del();
						}
					});
				}
				return false;
			});
		});
</script>